package com.example.archive.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.archive.entity.ArchiveModificationRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ArchiveModificationRequestMapper extends BaseMapper<ArchiveModificationRequest> {
    
    @Select("SELECT amr.*, " +
            "COALESCE(u1.name, u1.username) as applicant_name, " +
            "COALESCE(u2.name, u2.username) as approver_name, " +
            "COALESCE(u3.name, u3.username) as executor_name, " +
            "a.title as archive_title " +
            "FROM archive_modification_requests amr " +
            "LEFT JOIN users u1 ON amr.applicant_id = u1.user_id " +
            "LEFT JOIN users u2 ON amr.approver_id = u2.user_id " +
            "LEFT JOIN users u3 ON amr.executor_id = u3.user_id " +
            "LEFT JOIN archives a ON amr.archive_id = a.archive_id " +
            "ORDER BY amr.apply_time DESC")
    Page<ArchiveModificationRequest> selectRequestsWithDetails(Page<ArchiveModificationRequest> page);
} 